#-*- coding:utf-8 -*-

from steam_data_collect.func_pack import ip_handles
import logging
loger=logging.getLogger(__file__)

class proxy_ip_downloader_middleware(object):
    def process_request(self,request, spider):
        if spider.name=="nasa_steam":
            # ip_obj=ip_handles()
            # ip,port=ip_obj.get_one_ip_port()
            ip="127.0.0.1"
            port=1205
            if ip!=None and port!=None:
                if request.url.startswith("http://"):
                    request.meta['http_proxy'] = "http://%s:%d" % (ip, int(port))
                    loger.info(u"使用代理 {}".format(request.meta['http_proxy']))
                if request.url.startswith("https://"):
                    request.meta['https_proxy'] = "https://%s:%d" % (ip, int(port))
                    loger.info(u"使用代理 {}".format(request.meta['https_proxy']))


